﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kugar.Core.ExtMethod;

namespace Kugar.Tools.SQLHelper.SQLGenerator
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    public class DbTableStructInfo
    {
        public string Name { set; get; }

        /// <summary>
        /// 类型: 0=表 1=视图
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 表备注
        /// </summary>
        public string Comment { set; get; }

        public DbTableInfo_Column[] Columns { set; get; }

        public Table_Index[] Indexes { set; get; }

        public override string ToString()
        {
            return Name;
        }
    }

    /// <summary>
    /// 表索引
    /// </summary>
    public class Table_Index
    {
        public string IndexName { set; get; }

        /// <summary>
        /// 列名
        /// </summary>
        public Column[] Colunms { set; get; }

        /// <summary>
        /// 是否唯一列
        /// </summary>
        public bool IsUnique { set; get; }

        /// <summary>
        /// 是否自动忽略重复键
        /// </summary>
        public bool IsIgnoreDueKey { set; get; }

        public bool IsPrimary { set; get; }

        

        public class Column
        {
            public string ColumnName { set; get; }

            public string Type { set; get; }

            /// <summary>
            /// 是否是降序
            /// </summary>
            public bool IsDesc { set; get; }
        }
    }

    public class TableIndex_MySQLIndexColumn: Table_Index.Column
    {
        
    }

    public class DbTableInfo_Column
    {
        public string Name { set; get; }

        /// <summary>
        /// 列类型 0=数据列  1=计算列
        /// </summary>
        public int ColumnType { get; set; }

        /// <summary>
        /// 是否可空
        /// </summary>
        public bool IsNullable { set; get; }

        /// <summary>
        /// 是否是主键
        /// </summary>
        public bool IsPrimaryKey { set; get; }

        /// <summary>
        /// 是否是自增量列
        /// </summary>
        public bool IsAutoInc { set; get; }

        /// <summary>
        /// 列备注
        /// </summary>
        public string Comment { get; set; }

        /// <summary>
        /// 列的值类型
        /// </summary>
        public string ValueType { set; get; }

        public int Size { set; get; }

        /// <summary>
        /// 小数点个数
        /// </summary>
        public int Digit { set; get; }

    }

    /// <summary>
    /// 存储过程信息
    /// </summary>
    public class DbProcInfo
    {
        public string ProcName { set; get; }

        public ParameterInfo[] Parameters { set; get; }

        public string ParameterToString
        {
            get
            {
                return Parameters.Select(x => $"{x.TypeName}{(x.Length > 0 ? $"({x.Length})" : "")} {x.ParameterName}")
                    .JoinToString();
            }
        }

        public class ParameterInfo
        {
            public int Index { set; get; }

            public string ParameterName { set; get; }

            public string TypeName { set; get; }

            public int Length { set; get; }

            public ParameterDirection Direction { set; get; }

            public bool IsNullable { set; get; }
        }
    }
}
